/**
 * FileName: indexCharts
 * Create by fengzheng on 2019/4/28 23:05
 * Description:
 */

var myCharts = echarts.init(document.getElementById('right_panel_chart'));
var myOptions = {
    xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
        type: 'value'
    },
    series: [{
        type: 'line',
        smooth: true
    }]
};

function sensorRequest() {
    $.ajax({
        url:"queryData",
        timeout:60000,
        type:"post",
        data:{"sn":200},
        dataType:"JSON",
        error:function (error) {
            responseError(error);
        },
        success:function (successData) {
            drawChart(successData);
        }
    });
}


function drawChart(result) {
    if(typeof result === "string"){
        result = JSON.parse(result);
    }

    let responseBody;
    if(result.status === "ok"){
        responseBody = result.info;
    }

    let responseData = [];
    for(let key in responseBody){
        responseData.push(key.value);
    }

    myOptions.series[0].data = responseData;
    myCharts.setOption(myOptions);
}